package com.example.clxy.controller;

import com.example.clxy.entity.Question;
import com.example.clxy.entity.dto.QuestionDto;
import com.example.clxy.entity.dto.QuestionDto2;
import com.example.clxy.interceptor.AppToken;
import com.example.clxy.result.PageResult;
import com.example.clxy.result.PageResultForQuestion;
import com.example.clxy.result.WebRestResult;
import com.example.clxy.result.business.PageResult.QuestionPageResult;
import com.example.clxy.result.business.QuestionResult;
import com.example.clxy.service.QuestionService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author Hsieh
 * @title: QuestionController
 * @projectName clxy
 * @description: 题库控制器
 * @date 2020/8/520:03
 */
@AppToken
@RestController
@RequestMapping("QuestionController")
public class QuestionController {

    @Autowired
    QuestionService questionService;


    /**
     * @param
     * @Author:hsieh
     * @Date: 2020/8/5 20:22
     * @Description:增加题目
     */
    @CrossOrigin
    @PostMapping("addQuestion")
    public Map<String, Object> addQuestion(@RequestBody Question question) {
        Map<String, Object> result = questionService.addQuestion(question);
        return result;
    }

    /**
     * @param
     * @Author:hsieh
     * @Date: 2020/8/5 20:22
     * @Description:删除题目
     */
    @CrossOrigin
    @PostMapping("deleteQuestion")
    public WebRestResult deleteQdeleteQuestionuestion(String questionid) {
        WebRestResult result = questionService.deleteQuestion(questionid);
        return result;
    }

    /**
     * @param
     * @Author:hsieh
     * @Date: 2020/8/5 20:22
     * @Description:更新题目
     */

    @Data
    public class Questionwithlocation {
        Question question;
        String experiment;
        String platform;

        public Question getQuestion() {
            return question;
        }

        public void setQuestion(Question question) {
            this.question = question;
        }

        public String getExperiment() {
            return experiment;
        }

        public void setExperiment(String experiment) {
            this.experiment = experiment;
        }

        public String getPlatform() {
            return platform;
        }

        public void setPlatform(String platform) {
            this.platform = platform;
        }
    }

    @CrossOrigin
    @PostMapping("updateQuestion")
    public WebRestResult updateQuestion(@RequestBody QuestionDto2 questionDto2) {

        WebRestResult result = questionService.updateQuestion(questionDto2);

        return result;
    }

    /**
     * @param
     * @Author:hsieh
     * @Date: 2020/8/5 20:22
     * @Description:获取题目列表 "title"为空则为查询全部，不为空则为模糊查询
     */
    @CrossOrigin
    @RequestMapping("getQuestionList")
    public PageResult<QuestionPageResult> getQuestionList(String content, int page, int pagesize) {
        PageResult<QuestionPageResult> result = questionService.getQuestionList(content, page, pagesize);
        return result;
    }

    /**
     * @param
     * @Author:hsieh
     * @Date: 2020/8/6 16:02
     * @Description:将实验与试题绑定
     */
    @CrossOrigin
    @PostMapping("ExperimentbindQuestion")
    public WebRestResult ExperimentbindQuestion(String experimentid, String questionid) {
        WebRestResult result = questionService.ExperimentbindQuestion(experimentid, questionid);
        return result;
    }


    /**
     * @param
     * @Author:hsieh
     * @Date: 2020/8/6 16:03
     * @Description:将平台与试题绑定
     */
    @CrossOrigin
    @PostMapping("PlatformbindQuestion")
    public WebRestResult PlatformbindQuestion(String platformid, String questionid) {
        WebRestResult result = questionService.PlatformbindQuestion(platformid, questionid);
        return result;
    }


    /**
     * @param
     * @Author:hsieh
     * @Date: 2020/8/9 9:49
     * @Description:获取某实验下的试题
     */
    @CrossOrigin
    @RequestMapping("getQuestionListbyExperiment")
    public PageResult<QuestionPageResult> getQuestionListbyExperiment(String experimentid, String content, int page, int pagesize) {
        PageResult<QuestionPageResult> result = questionService.getQuestionListbyExperiment(experimentid, content, page, pagesize);
        return result;
    }

    @CrossOrigin
    @RequestMapping("getQuestionListbyPlatform")
    public PageResult<QuestionPageResult> getQuestionListbyplatform(String platformid, String content, int page, int pagesize) {
        PageResult<QuestionPageResult> result = questionService.getQuestionListbyPlatform(platformid, content, page, pagesize);
        return result;
    }

    @CrossOrigin
    @RequestMapping("getallQuestionListwithExperiment")
    public PageResult<QuestionPageResult> getallQuestionListwithExperiment(String content, int page, int pagesize) {
        PageResult<QuestionPageResult> result = questionService.getallQuestionListwithExperiment(content, page, pagesize);
        return result;
    }

    @CrossOrigin
    @RequestMapping("getallQuestionListwithPlatform")
    public PageResult<QuestionPageResult> getallQuestionListwithPlatform(String content, int page, int pagesize) {
        PageResult<QuestionPageResult> result = questionService.getallQuestionListwithPlatform(content, page, pagesize);
        return result;
    }

    /**
     * @param
     * @Author:hsieh
     * @Date: 2020/8/9 9:51
     * @Description:根据id查试题
     */
    @CrossOrigin
    @RequestMapping("getQuestionbyId")
    public QuestionResult getQuestionbyId(String questionid) {
        QuestionResult result = questionService.getQuestionbyId(questionid);
        return result;
    }


    /**
     * 新增一个题目并勾选多个平台\\\\\\
     * ]
     *
     * @param questionDto
     * @return
     */
    @CrossOrigin
    @PostMapping("addQuestionMuti")
    public WebRestResult addQuestionMuti(@RequestBody QuestionDto questionDto) {
        WebRestResult result = questionService.addQuestionMuti(questionDto);
        return result;
    }


    /**
     * 更新一个题目并勾选多个平台
     * ]
     *
     * @param questionDto
     * @return
     */
    @CrossOrigin
    @PostMapping("updateQuestionMuti")
    public WebRestResult updateQuestionMuti(@RequestBody QuestionDto questionDto) {
        WebRestResult result = questionService.updateQuestionMuti(questionDto);
        return result;
    }


    /**
     * @param
     * @Author:hsieh
     * @Date: 2020/8/18 16:38
     * @Description:按照比例分别调用平台和实验的题目
     */
    @CrossOrigin
    @RequestMapping("getQuestionApartmently")
    public PageResult<QuestionPageResult> getQuestionApartmently(String platformid, String experimentid, int page, int pagesize) {
        PageResult<QuestionPageResult> result = questionService.getQuestionApartmently(platformid, experimentid, page, pagesize);
        return result;
    }

    @CrossOrigin
    @RequestMapping("isPassSafetyAssessment")
    public WebRestResult isPassSafetyAssessment(String scheduleid, String studentid, String status) {
        WebRestResult result = questionService.isPassSafetyAssessment(scheduleid, studentid, status);
        return result;
    }


}
